package com.itic.mall.system.incomelog.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.constants.IticConst;
import com.itic.appbase.framework.common.constants.ResponseCode;
import com.itic.appbase.framework.common.controller.BaseController;
import com.itic.mall.system.incomelog.persistence.model.IncomeLog;
import com.itic.mall.system.incomelog.persistence.model.IncomeLogExample;
import com.itic.mall.system.incomelog.service.IncomeLogService;


@Controller
@RequestMapping(value="/system/incomelog")
public class IncomeLogController
     extends BaseController {
    @Autowired
    private IncomeLogService incomeLogService;

    //////////////////////////////////////////////////////常量区////////////////////////////////////////////////////////////////
    private static final String MODEL_NAME_CHINA = "支入管理";//中文名
    private static final String MODEL_NAME＿ENGLISH = "incomelog";//英文名
    private static final String PAGE_COMMON_PATH = "/mall/system/incomelog/incomelog";//通用路径
    private static final String COMMON_URL = "/system/incomelog/";//通用路径

    //////////////////////////////////////////////////////页面跳转区////////////////////////////////////////////////////////////
   
    /*
     * 主页面
     */
    @RequestMapping(value="/init")
    public String init(Model model){
    	model.addAttribute("name_china", MODEL_NAME_CHINA);
    	model.addAttribute("name_english", MODEL_NAME＿ENGLISH);
    	model.addAttribute("common_url", COMMON_URL);
    	return PAGE_COMMON_PATH+"Main";
    }
    
    
    
    //////////////////////////////////////////////////////业务代码区////////////////////////////////////////////////////////////
    
    
    
    /**
     * <p>Title:queryCondition </p>
     * <p>Description:封装查询条件 </p>
     * @param jzdw
     * @param jzdwExample
     * @return
     */
    private IncomeLogExample queryCondition(HttpServletRequest request,IncomeLog temp) {
    	
    	// 参数处理
        IncomeLogExample example = new IncomeLogExample();
        // 按创建时间倒序
        example.setOrderByClause("CREATE_TIME DESC");
        // 按排列号顺序
        
        example.createCriteria().andIsEffectiveEqualTo( DBConst.TRUE );
        
       
        return example;
    }
    
    /**
     * 
     * @param goldType
     * @param request
     * @return
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Map<String, Object> list(IncomeLog IncomeLog, HttpServletRequest request){
        // 声明返回对象
        Map<String, Object> resultMap = new HashMap<String, Object>();
        
        
        IncomeLogExample example = this.queryCondition(request,IncomeLog);
        // 封装分页参数
        example = this.handlePageQuery(request, example);
        
        
        // 获取信息总条数
        int total = incomeLogService.count(example);
        
        // 获取数据
        List<IncomeLog> list = incomeLogService.list(example);
        
        // 数据返回处理
        resultMap.put(IticConst.TOTAL_RECORDS, total);
        resultMap.put(IticConst.DISPLAY_RECORDS, total);
        resultMap.put(IticConst.RESULT, ResponseCode.SUCCESS.getCode());
        resultMap.put(IticConst.DATA, list);
        return resultMap;

    }
    
   
}